<template>
	<u-popup v-model="show" mode="center" border-radius="24">
		<view class="warning-pop-content">
			<view class="header-title">
				<text>修改名称</text>
				<image @click="handleClose"
					src="https://20250520wtjsq.xinyunweb.com/uploads/images/20250803/202508032340300ec747360.png"
					mode="aspectFill" class="close-icon">
				</image>
			</view>
			<view class="name-content">
				<u-input v-model="name" placeholder="请输入名称" border :maxlength="20" />
			</view>
			<view class="footer-box">
				<u-button type="primary" @click="handleConfirm">确定</u-button>
			</view>
		</view>
	</u-popup>
</template>

<script>
	import { request, toast, showLoading } from '@/utils/tool'
	export default {
		data() {
			return {
				show: false,
				name: '',
				deviceId: ""
			}
		},
		emits: ["success"],
		methods: {
			async handleConfirm() {
				const { deviceId, name } = this
				if (!deviceId) return
				if (!name) return toast({ title: "请输入名称" })
				const hide = showLoading("正在修改")
				const resp = await request({
					url: "/shebei/editshebeijiancheng",
					data: {
						jiancheng: name,
						shebei_id: deviceId
					}
				}).catch(hide)
				if (resp.code !== 1) {
					toast({ title: resp.msg || "修改失败" })
					return hide()
				}
				hide()
				toast("修改成功")
				this.handleClose()
				this.$emit("success")
			},
			open(deviceId, name) {
				this.show = true
				this.deviceId = deviceId
				this.name = name
			},
			handleClose() {
				this.show = false
				setTimeout(() => {
					this.name = ""
					this.deviceId = ""
				}, 300)
			}
		},
	}
</script>

<style lang="scss" scoped>
	.warning-pop-content {
		padding: 46rpx 54rpx 50rpx;
		width: 599rpx;
		box-sizing: border-box;

		.footer-box {
			margin-top: 40rpx;
			padding: 0 88rpx;
		}

		.close-icon {
			width: 40rpx;
			height: 40rpx;
			position: absolute;
			top: 50%;
			right: 16rpx;
			transform: translateY(-50%);
		}

		.header-title {
			font-weight: 400;
			font-size: 32rpx;
			color: #000000;
			letter-spacing: 1px;
			line-height: 44rpx;
			text-align: center;
			position: relative;
		}

		.name-content {
			padding: 40rpx 0;
			box-sizing: border-box;
			margin-top: 24rpx;
		}

	}
</style>